﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Repositories;
using Repositories.Interfaces;

namespace AsiaSnackExpress
{
    public partial class DetailCombo : System.Web.UI.UserControl
    {
        private IComboRepository _comboRep;


        public IComboRepository ComboRep
        {
            get
            {
                if (this._comboRep == null)
                    this._comboRep = DIHelper.Resolve<IComboRepository>();
                return this._comboRep;
            }
        }

        public int ComboOrder { get; set; }

        public bool Active { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Active)
                this.divContainer.Style["display"] = "block";
            Combo allComboByOrder = this.ComboRep.GetComboByOrder(this.ComboOrder);
            if (allComboByOrder == null)
                return;
            this.ltlName.Text = allComboByOrder.NameByLanguage;
            string comboName;
            if (allComboByOrder.NameByLanguage.IndexOf("(") > 0)
            {
                comboName = allComboByOrder.NameByLanguage.Substring(0, allComboByOrder.NameByLanguage.IndexOf("("));
            }
            else
            {
                comboName = allComboByOrder.NameByLanguage;
            }
            ltlNameInSide.Text = comboName;
            if (allComboByOrder.Price != null)
                this.ltlPrice.Text = allComboByOrder.Price.Value.ToString("0.00€", (IFormatProvider)CultureInfo.InvariantCulture);
            this.ltlDetail.Text = allComboByOrder.MealsByLanguage;
            this.divContent.Style.Add("background", string.Format("url('/images/{0}') no-repeat scroll 100% 0 transparent", allComboByOrder.Image));
        }
    }
}